package controller

import (
	"github.com/exam/api/request"
	"github.com/exam/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type UserController struct {
	service service.IUserService
}

func NewUserController(service service.IUserService) *UserController {
	return &UserController{
		service: service,
	}
}

func (u *UserController) Login(c *gin.Context) {
	var req request.User
	err := c.ShouldBind(&req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error:": "参数获取失败" + err.Error()})
		return
	}
	err, login := u.service.Login(c, req)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error:": "登录失败" + err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": "200", "msg": "登录成功", "data": login})

}
